*==============================================================================
*==============================================================================
*=     File-Name:      DataAnalysis.do                                       == 
*=     Date:           11/28/2024                                            ==
*=     Author:         Murat Abus (muabus@syr.edu)                           ==
*=     Purpose:        Replicate the analysis in Abus (PRQ 2025)            == 
*=     Input File 1:   GenderCandidate.dta                                   ==
*=     Input File 2:   GenderCandidateCompact.dta                            ==
*=     Machine:        Lenovo ThinkPad E570                                  == 
*=     System:         Ubuntu 24.04.1 LTS / GNOME 46                         ==
*==============================================================================
*==============================================================================

clear
pwd
version 16.1
// capture log close
set more off


// Replicate Analysis in Abus PRQ (2025).

// Load Data 

use "GenderCandidate.dta", clear
describe

// Table 1

ttest office if gender == 2, by(partpos)
return list

ttest timenominavg if gender == 2, by(partpos) 
return list

ttest listpos if gender == 2, by(partpos)   
return list 

ttest timeorgavg if gender == 2 , by(partpos)
return list

ttest winner if gender == 2, by(partpos)
return list 

// Table 2 in Supplemental Material

summ WL WR ML MR listpos age educ educnew govparbef govpartyb govparaft govpartya partypos partpos distmag incumbcan cl pluralty pr housesys threshold female diff diffnew gender winner timenomin timeorg officenew  

// Correlation matrix for the main independent variable and control variables
pwcorr WL diff govparbef govparaft age incumbcan educ cl pluralty distmag office threshold, sig


// Table 2 in Main Text
use "GenderCandidate", replace

// Model 1
mixed office WL##c.diff govparbef govparaft age incumbcan cl pluralty distmag threshold if gender == 2 || t1:, robust

eststo model1: qui mixed office WL##c.diff govparbef govparaft age incumbcan cl pluralty distmag threshold if gender == 2 || t1:, robust

// Model 2
use "GenderCandidateCompact.dta", clear

meologit timenomin WL##c.diff govparbef govparaft age incumbcan cl pluralty distmag threshold || t1:, vce(robust)

eststo model2: qui meologit timenomin WL##c.diff govparbef govparaft age incumbcan cl pluralty distmag threshold || t1:, vce(robust)

// Model 3
use "GenderCandidate", replace

mixed listpos WL##c.diff govparbef govparaft age incumbcan cl pluralty distmag threshold if gender == 2 || t1:, robust

eststo model3: qui mixed listpos WL##c.diff govparbef govparaft age incumbcan cl pluralty distmag threshold if gender == 2 || t1:, robust

// Model 4
use "GenderCandidateCompact.dta", clear

meologit timeorg WL##c.diff govparbef govparaft age incumbcan cl housesys distmag threshold || t1:, vce(robust)

eststo model4: qui meologit timeorg WL##c.diff govparbef govparaft age incumbcan cl housesys distmag threshold || t1:, vce(robust)

// Model 5
use "GenderCandidate", replace
melogit winner WL##c.diff govparbef govparaft age incumbcan cl pluralty distmag threshold if gender == 2 || t1:, vce(robust)

eststo model5: qui melogit winner WL##c.diff govparbef govparaft age incumbcan cl pluralty distmag threshold if gender == 2 || t1:, vce(robust)

esttab model1 model2 model3 model4 mode5 using "table2.tex", replace b(%9.3g) se label aic bic r2 nogap ///  
nonumbers mtitle("I") title("Candidate Differences (Women)")

clear

use "GenderCandidate", clear

// MARGINAL EFFECTS PLOTS (MAIN TEXT)

mkdir marginplots

// Graph one (Office Holding Experience)
qui mixed office WR##c.diff govparbef govparaft age incumbcan cl housesys distmag threshold if gender == 2 || t1:, robust

qui margins WR, post

coefplot, vertical title(Office Experience) xlabel(1 "Left" 2 "Right") mcolor("0 0 0") ciopts(lcolor("105 105 105")) levels(83) 

graph save marginplots/margins1.gph, replace

use "GenderCandidateCompact", clear 

// Graph two (Nomination Time)
qui mixed timenomin WR##c.diff govparbef govparaft age incumbcan cl housesys distmag threshold || t1:, vce(robust)

qui margins WR, post

coefplot, vertical title(Nomination Time) xlabel(1 "Left" 2 "Right") mcolor("0 0 0") ciopts(lcolor("105 105 105")) levels(83) 

graph save marginplots/margins2.gph, replace

use "GenderCandidate", clear

// Graph three (List Position)
qui mixed listpos WR##c.diff govparbef govparaft age incumbcan cl housesys distmag threshold if gender == 2 || t1:, robust

qui margins WR, post

coefplot, vertical title(List Position) xlabel(1 "Left" 2 "Right") mcolor("0 0 0") ciopts(lcolor("105 105 105")) levels(83)

graph save marginplots/margins3.gph, replace

use "GenderCandidateCompact", clear 

// Graph four (Campaign Organization)
qui mixed timeorg WR##c.diff govparbef govparaft age incumbcan cl housesys distmag threshold || t1:, vce(robust)

qui margins WR, post

coefplot, vertical title(Campaign Organization) xlabel(1 "Left" 2 "Right") mcolor("0 0 0") ciopts(lcolor("105 105 105")) levels(83) 

graph save marginplots/margins4.gph, replace

use "GenderCandidate", clear

// Graph five (Winning)
qui melogit winner WR##c.diff govparbef govparaft age incumbcan cl housesys distmag threshold || t1:, vce(robust)

qui margins WR, post

coefplot, vertical title(Winning) xlabel(1 "Left" 2 "Right") mcolor("0 0 0") ciopts(lcolor("105 105 105")) levels(83)

graph save marginplots/margins5.gph, replace

// Now to combine the graphs into one image:
graph combine marginplots/margins1.gph marginplots/margins2.gph marginplots/margins3.gph marginplots/margins4.gph marginplots/margins5.gph,rows(2) graphregion(fcolor(white)) l1(Predicted Values, size(medium)) b1(Women Candidates, size(medium)) 

graph save marginplots/figure1.gph, replace 
graph export marginplots/figure1.pdf, replace
graph export marginplots/figure1.svg, replace
graph export marginplots/figure1.png, replace

clear 

// SUPPLEMENTAL INFORMATION 

// Appendix A Robustness Checks
// Appendix A.1 

// The changes are the substitution of the government change variables with three-item collapsed variables and a new difference variable, the substitution of the seven-item educational level variable with a collapsed four-item variable and finally the substitution of a variable tracking how early candidates start campaigning full-time for the dependent variable that tracks how early the candidates start organizing their campaigns. 


use "GenderCandidate", clear

// Model 1
mixed office WL diffnew govpartyb govpartya age incumbcan cl housesys distmag threshold if gender == 2 || t1:, robust

eststo model1: qui mixed office WL diffnew govpartyb govpartya age incumbcan cl housesys distmag threshold if gender == 2 || t1:, robust

use "GenderCandidateCompact", clear

// Model 2
meologit timenomin WL diffnew govpartyb govpartya age incumbcan cl housesys distmag threshold || t1:, vce(robust)

eststo model2: qui meologit timenomin WL diffnew govpartyb govpartya age incumbcan cl housesys distmag threshold || t1:, vce(robust)

use "GenderCandidate", clear
 
// Model 3
mixed listpos WL diffnew govpartyb govpartya age incumbcan cl housesys distmag threshold if gender == 2 || t1:, robust

eststo model3: qui mixed listpos WL diffnew govpartyb govpartya age incumbcan cl housesys distmag threshold if gender == 2 || t1:, robust

use "GenderCandidateCompact", clear

// Model 4
meologit timeorg WL diffnew govpartyb govpartya age incumbcan cl housesys distmag threshold || t1:, vce(robust)

eststo model4: qui meologit timeorg WL diffnew govpartyb govpartya age incumbcan cl housesys distmag threshold || t1:, vce(robust)

use "GenderCandidate", clear

// Model 5
melogit winner WL diffnew govpartyb govpartya age incumbcan cl housesys distmag threshold if gender == 2 || t1:, vce(robust)

eststo model5: qui melogit winner WL diffnew govpartyb govpartya age incumbcan cl housesys distmag threshold if gender == 2 || t1:, vce(robust)

// Model 6
mixed office WL##c.diffnew govpartyb govpartya age incumbcan cl housesys distmag threshold if gender == 2 || t1:, robust

eststo model6: qui mixed office WL diffnew govpartyb govpartya age incumbcan cl housesys distmag threshold if gender == 2 || t1:, robust

use "GenderCandidateCompact", clear

// Model 7
meologit timenomin WL##c.diffnew govpartyb govpartya age incumbcan cl housesys distmag threshold || t1:, vce(robust)

eststo model7: qui meologit timenomin WL##c.diffnew govpartyb govpartya age incumbcan cl housesys distmag threshold || t1:, vce(robust)

use "GenderCandidate", clear
 
// Model 8
mixed listpos WL##c.diffnew govpartyb govpartya age incumbcan cl housesys distmag threshold if gender == 2 || t1:, robust

eststo model8: qui mixed listpos WL##c.diffnew govpartyb govpartya age incumbcan cl housesys distmag threshold if gender == 2 || t1:, robust

use "GenderCandidateCompact", clear

// Model 9
meologit timeorg WL##c.diffnew govpartyb govpartya age incumbcan cl housesys distmag threshold || t1:, vce(robust)

eststo model9: qui meologit timeorg WL##c.diffnew govpartyb govpartya age incumbcan cl housesys distmag threshold || t1:, vce(robust)

use "GenderCandidate", clear

// Model 10
melogit winner WL##c.diffnew govpartyb govpartya age incumbcan cl housesys distmag threshold if gender == 2 || t1:, vce(robust)

eststo model10: qui melogit winner WL##c.diffnew govpartyb govpartya age incumbcan cl housesys distmag threshold if gender == 2 || t1:, vce(robust)


esttab model1 model2 model3 model4 model5 model6 model7 model8 model9 model10 using "appendixa1.tex", replace b(%9.3g) se label aic bic r2 nogap ///  
nonumbers mtitle("I") title("Candidate Differences--Robustness Check")

clear

// Appendix A.2

use "GenderCandidate", clear

// Model 1
mixed office WL##c.diff i.country govparbef govparaft incumbcan age if gender == 2 || t1:

eststo model1: qui mixed office WL##c.diff i.country govparbef govparaft incumbcan age if gender == 2 || t1:

use "GenderCandidateCompact.dta", clear

// Model 2
meologit timenomin WL##c.diff i.t1 govparbef govparaft incumbcan age || t1:

eststo model2: qui meologit timenomin WL##c.diff i.t1 govparbef govparaft incumbcan age || t1:

use "GenderCandidate", clear

// Model 3
mixed listpos WL##c.diff i.country govparbef govparaft incumbcan age if gender == 2 || t1:

eststo model3: qui mixed listpos WL##c.diff i.country govparbef govparaft incumbcan age if gender == 2  || t1:

use "GenderCandidateCompact.dta", clear

// Model 4
meologit timeorg WL##c.diff i.t1 govparbef govparaft incumbcan age || t1:

eststo model4: qui meologit timeorg WL##c.diff i.t1 govparbef govparaft incumbcan age || t1:

use "GenderCandidate", clear

// Model 5
melogit winner WL##c.diff i.country govparbef govparaft incumbcan age if gender == 2 || t1:

eststo model5: qui melogit winner WL##c.diff i.country govparbef govparaft incumbcan age if gender == 2 || t1:

esttab model1 model2 model3 model4 model5 using "appendixa2.tex", replace b(%9.3g) se label aic bic r2 nogap ///  
nonumbers mtitle("I") title("Candidate Differences")

clear

// Appendix A.3

/* 
A main concern can be that my results are not just for women but hold for men as well. In which case, it would be harder to make the case for a gender difference argument. The following analyses run the t-tests and the multivariate models in the paper for men candidates to show that the same processes do not work for men candidates. */

// Table 3 (Appendix)

use "GenderCandidate", clear
keep if gender == 1 // subsetting for the following analysis

ttest office, by(partpos)
return list

ttest timenominavg, by(partpos)
return list

ttest listpos, by(partpos)   
return list 

ttest timeorgavg, by(partpos)
return list

ttest winner, by(partpos)
return list 

clear 

// Table 4 (Appendix) 

use "GenderCandidate", clear

// Model 1
mixed office ML##c.diff govparbef govparaft incumbcan age cl pluralty distmag threshold if gender == 1 || t1:, robust

eststo model1: qui mixed office ML##c.diff govparbef govparaft incumbcan age cl pluralty distmag threshold if gender == 1 || t1:, robust

// Model 2
meologit timenomin ML##c.diff govparbef govparaft incumbcan age cl pluralty distmag threshold if gender == 1 || t1:, vce(robust)

eststo mdoel2: qui meologit timenomin ML##c.diff govparbef govparaft incumbcan age cl pluralty distmag threshold if gender == 1 || t1:, vce(robust)

// Model 3
mixed listpos ML##c.diff govparbef govparaft incumbcan age cl pluralty distmag threshold if gender == 1|| t1:, robust

eststo model3: qui mixed listpos ML##c.diff govparbef govparaft incumbcan age cl pluralty distmag threshold if gender == 1|| t1:, robust

// Model 4
meologit timeorg ML##c.diff govparbef govparaft incumbcan age cl pluralty distmag threshold if gender == 1 || t1:, vce(robust)

eststo model4: qui meologit timeorg ML##c.diff govparbef govparaft incumbcan age cl pluralty distmag threshold if gender == 1  || t1:, vce(robust)

// Model 5
melogit winner ML##c.diff govparbef govparaft incumbcan age cl pluralty distmag threshold if gender == 1  || t1:, vce(robust)

eststo model5: qui melogit winner ML##c.diff govparbef govparaft incumbcan age cl pluralty distmag threshold if gender == 1 || t1:, vce(robust)

esttab model1 model2 model3 model4 model5 using "appendixa3.tex", replace b(%9.3g) se label aic bic r2 nogap ///  
nonumbers mtitle("I") title("Candidate Differences (Men)")

// End of Supplementary Information
// End of Do-File
